﻿<UserControl x:Class="Waf.InformationManager.EmailClient.Modules.Presentation.Views.EmailView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:s="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.Selectors"
             xmlns:dd="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.DesignData"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DataContext="{d:DesignInstance dd:SampleEmailViewModel, IsDesignTimeCreatable=True}" 
             d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <Style TargetType="Label" BasedOn="{StaticResource {x:Type Label}}">
            <Setter Property="Padding" Value="5,3"/>
        </Style>
    </UserControl.Resources>
    
    <DockPanel>
        <ContentControl Content="{Binding Email}" DockPanel.Dock="Top" Margin="0,7,0,0">
            <ContentControl.ContentTemplate>
                <DataTemplate>
                    <Grid DockPanel.Dock="Top">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="60"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition>
                                <RowDefinition.Style>
                                    <Style TargetType="RowDefinition">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding CC.Count}" Value="0">
                                                <Setter Property="Height" Value="0"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                        <Setter Property="Height" Value="Auto"/>
                                    </Style>
                                </RowDefinition.Style>
                            </RowDefinition>
                            <RowDefinition>
                                <RowDefinition.Style>
                                    <Style TargetType="RowDefinition">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Bcc.Count}" Value="0">
                                                <Setter Property="Height" Value="0"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                        <Setter Property="Height" Value="Auto"/>
                                    </Style>
                                </RowDefinition.Style>
                            </RowDefinition>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.Resources>
                            <Style TargetType="Label" BasedOn="{StaticResource {x:Type Label}}">
                                <Setter Property="Margin" Value="0"/>
                            </Style>
                        </Grid.Resources>

                        <Label Content="Title:" Grid.Row="0" Grid.Column="0" Margin="11,0,0,0"/>
                        <Label Content="{Binding Title}" FontWeight="SemiBold" Grid.Row="0" Grid.Column="1"/>

                        <Label Content="From:" Grid.Row="1" Grid.Column="0" Margin="11,0,0,0"/>
                        <Label Content="{Binding From}" Grid.Row="1" Grid.Column="1"/>

                        <Label Content="To:" Grid.Row="2" Grid.Column="0" Margin="11,0,0,0"/>
                        <Label Grid.Row="2" Grid.Column="1">
                            <TextBlock Text="{Binding To, Converter={StaticResource StringCollectionToStringConverter}}" TextTrimming="CharacterEllipsis" />
                        </Label>

                        <Label Content="CC:" Grid.Row="3" Grid.Column="0" Margin="11,0,0,0"/>
                        <Label Grid.Row="3" Grid.Column="1">
                            <TextBlock Text="{Binding CC, Converter={StaticResource StringCollectionToStringConverter}}" TextTrimming="CharacterEllipsis"/>
                        </Label>

                        <Label Content="BCC:" Grid.Row="4" Grid.Column="0" Margin="11,0,0,0"/>
                        <Label Grid.Row="4" Grid.Column="1">
                            <TextBlock Text="{Binding Bcc, Converter={StaticResource StringCollectionToStringConverter}}" TextTrimming="CharacterEllipsis"/>
                        </Label>

                        <Label Content="Sent:" Grid.Row="5" Grid.Column="0" Margin="11,0,0,0"/>
                        <Label Content="{Binding Sent}" Grid.Row="5" Grid.Column="1"/>
                    </Grid>
                </DataTemplate>
            </ContentControl.ContentTemplate>
        </ContentControl>

        <FlowDocumentReader Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,7,0,0" 
                            BorderThickness="0,1,0,0" BorderBrush="{x:Static SystemColors.ActiveBorderBrush}">
            <FlowDocument TextAlignment="Left" FontSize="14" LineHeight="24" IsOptimalParagraphEnabled="True" IsHyphenationEnabled="True">
                <Paragraph>
                    <Run Text="{Binding Email.Message}"/>
                </Paragraph>
            </FlowDocument>
        </FlowDocumentReader>
    </DockPanel>
</UserControl>
